import os
import time
import socket

import json
from pprint import pprint

file_path = '/user/config/jobstart_hccl.json'
with open(file_path, 'r') as f:
    info = f.read()

info = json.loads(info)

rank_count = len(info['group_list'][0]['instance_list'][0]['devices'])

host_url_list = os.environ.get("VC_WORKER_HOSTS").split(",")
ip_list = []
for host_url in host_url_list:
    ip = socket.gethostbyname(host_url)
    print(ip)
    ip_list.append(ip)

with open('hostfile', 'w') as f:
    for i in ip_list:
        f.write(f'{i} slot={rank_count}\n')